import { Controller, Post, Get, UseInterceptors, UploadedFiles, Body, Query } from '@nestjs/common';
import { DyService } from '@/modules/dy/dy.service';
import { DyUserActionHookService } from '@/modules/dy/dy.user.action.hook.service';
import { FileFieldsInterceptor } from '@nestjs/platform-express';
import { Express } from 'express';
@Controller("dy")
export class DyController {
  constructor(
    private readonly dyService: DyService,
    private readonly dyUserActionHookService: DyUserActionHookService,
  ) {
  }

  @Post("publish")
  @UseInterceptors(FileFieldsInterceptor([
    { name: 'cover', maxCount: 1 },
    { name: 'video', maxCount: 1 },
  ]))
  publish(@UploadedFiles() files: {cover: Express.Multer.File[], video: Express.Multer.File[]}, @Body() options: any) {
    const opt = {
      videoFile: files.video[0],
      coverFile: files.cover[0],
      config: options
    }
    return this.dyService.publish(opt)
  }

  @Get("/suggest/tag")
  suggestTag(@Query() query: {keyword: string}) {
    return this.dyService.suggestTag(query.keyword)
  }

  @Get("/hook/user")
  hook(@Query() query: {id: number}) {
    return this.dyUserActionHookService.fire(query.id)
  }

}